<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="客户名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应收余额" prop="recbalanceZK">
        <el-select v-model="queryParams.recbalanceZKCompare" size="mini" placeholder="请选择" clearable style="width: 85px">
          <el-option v-for="item in symbol" :label="item.name" :value="item.name" :key="item.id"/>
        </el-select>
        <el-input v-model="queryParams.recbalanceZK" clearable size="mini" @keyup.enter.native="handleQuery" placeholder="请输入金额" style="width: 107px"/>
      </el-form-item>
      <el-form-item label="预收余额" prop="prebalance">
        <el-select v-model="queryParams.prebalanceCompare" size="mini" placeholder="请选择" clearable style="width: 85px">
          <el-option v-for="item in symbol" :label="item.name" :value="item.name" :key="item.id"/>
        </el-select>
        <el-input v-model="queryParams.prebalance" clearable size="mini" @keyup.enter.native="handleQuery" placeholder="请输入金额" style="width: 107px"/>
      </el-form-item>
      <el-form-item label="日期" prop="beginTime">
        <el-date-picker v-model="queryParams.businessDateStart" type="date" value-format="yyyy-MM-dd" placeholder="开始日期" size="mini" clearable/> -
        <el-date-picker v-model="queryParams.businessDateEnd" type="date" value-format="yyyy-MM-dd" placeholder="结束日期" size="mini" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cusomerbalanceList" >
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="客户名称" align="center" prop="name" width="500px"/>
      <el-table-column label="业务日期" align="center" prop="businessDate" />
      <el-table-column label="金蝶编号" align="center" prop="kingdeenum"/>
      <el-table-column label="预收款余额" align="center" prop="prebalance" width="100px"/>
      <el-table-column label="应收账单余额" align="center" prop="recbalance" width="100px"/>
      <el-table-column label="应收款余额" align="center" prop="recbalanceZK" width="100px" />
      <el-table-column label="初始应收余额" align="center" prop="recbalanceManul" width="100px"/>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:cusomerbalance:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:cusomerbalance:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listCusomerbalance, exportCusomerbalance } from "@/api/customer/cusomerbalance";

export default {
  name: "CustomerBalance",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户余额表格数据
      cusomerbalanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      symbol:[{id:1,name:'>'},{id:2,name:'>='},{id:3,name:'<'},{id:4,name:'<='},{id:5,name: '='}],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        prebalance:null,
        recbalanceZK: null,
        customerguid: null,
        name:null,
        businessDateStart:null,
        businessDateEnd:null,
        recbalanceZKCompare:null,
        prebalanceCompare:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户余额列表 */
    getList() {
      if (this.queryParams.recbalanceZKCompare){
        if (this.queryParams.recbalanceZK==null || this.queryParams.recbalanceZK==''){
          this.queryParams.recbalanceZK=0
        }
      }else {
        this.queryParams.recbalanceZK=null
        this.queryParams.recbalanceZKCompare=null
      }
      if (this.queryParams.prebalanceCompare){
        if (this.queryParams.prebalance==null || this.queryParams.prebalance==''){
          this.queryParams.prebalance=0
        }
      }else {
        this.queryParams.prebalance=null
        this.queryParams.prebalanceCompare=null
      }
      if (this.queryParams.businessDateStart==''){
        this.queryParams.businessDateStart=null
      }
      if (this.queryParams.businessDateEnd==''){
        this.queryParams.businessDateEnd=null
      }
      this.loading = true;
      listCusomerbalance(this.queryParams).then(response => {
        this.cusomerbalanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        prebalance:null,
        recbalanceZK: null,
        name:null,
        businessDateStart:null,
        businessDateEnd:null,
        recbalanceZKCompare:null,
        prebalanceCompare:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.customername)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    // },
    /** 导出按钮操作 */
    handleExport() {
      if (this.queryParams.recbalanceZKCompare && this.queryParams.recbalanceZKCompare!=''){
        if (this.queryParams.recbalanceZK==null || this.queryParams.recbalanceZK==''){
          this.queryParams.recbalanceZK=0
        }
      }else {
        this.queryParams.recbalanceZK=null
        this.queryParams.recbalanceZKCompare=null
      }
      if (this.queryParams.prebalanceCompare && this.queryParams.prebalanceCompare!=''){
        if (this.queryParams.prebalance==null || this.queryParams.prebalance==''){
          this.queryParams.prebalance=0
        }
      }else {
        this.queryParams.prebalance=null
        this.queryParams.prebalanceCompare=null
      }
      if (this.queryParams.businessDateStart==''){
        this.queryParams.businessDateStart=null
      }
      if (this.queryParams.businessDateEnd==''){
        this.queryParams.businessDateEnd=null
      }
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户余额数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCusomerbalance(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
